AddCSLuaFile("cl_init.lua")
AddCSLuaFile("shared.lua")
include('shared.lua')

function ENT:Use(activator, caller)
	if !self.World && !self.dt.Sparking then self:CreateTimers() end
	self.dt.Sparking = true
	self.Active = true
	self:SetColor(255, 255, 255, 255)
end

function ENT:MakeDrug()
	local spos = self.SparkPos
	local ang = self:GetAngles()
	local drug = ents.Create("drug_booze")
	drug:SetPos(self:GetPos() + ang:Forward() * spos.x + ang:Right() * spos.y + ang:Up() * spos.z)
	drug:Spawn()
	
	self.dt.Sparking = false
end

function ENT:CreateTimers()
	timer.Create(tostring(self) .. "payday", self.PayDayTime, 0, self.PayDay, self)
	timer.Create(tostring(self) .. "makedrug",  math.random(self.DrugTimeMin, self.DrugTimeMax), 1, self.MakeDrug, self)
	timer.Create(tostring(self) .. "warnturnoff", self.TurnOffTime - (self.TurnOffTime * 0.1), 1, self.WarnTurnOff, self)
	timer.Create(tostring(self) .. "turnoff", self.TurnOffTime, 1, self.TurnOff, self)
end

function ENT:OnRemove()
	timer.Remove(tostring(self) .. "payday")
	timer.Remove(tostring(self) .. "makedrug")
	timer.Remove(tostring(self) .. "warnturnoff")
	timer.Remove(tostring(self) .. "turnoff")
end